<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>整车调度查看</title>
<meta name="decorator" content="default" />

<script type="text/javascript">
var tRealscheVehiRowIdx = 0, tRealscheVehiTpl = 'tRealscheVehiTpl';
		$(document).ready(function() {	
			var data = ${fns:toJson(tRealsche.tRealscheVehiList)};
			for (var i=0; i<data.length; i++){
				addRow('#tRealscheVehiList', i, tRealscheVehiTpl, data[i]);
			}
		});
		function addRow(list, idx, tpl, row){
			var data;

			// 加载后台的有默认值
			data = {idx: idx, row:row};
			var num=$("#tRealscheVehiList tr").length;
			
			var prefix = list + num;
			keypresstwo(row.busid, prefix);
			
			if (row.drvconfirmed == '0')
				row.drvconfirmed = '未确认';
			else
			if (row.drvconfirmed == '1')
				row.drvconfirmed = '已确认';
			else
			if (row.drvconfirmed == '2')
				row.drvconfirmed = '已完单';
			
			 //查询保存的上下客点信息
	    	var html = template(tpl, data); // 渲染模板    	
			$(list).append(html);
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
				$(this).find("option[selected='selected']").attr("selected",'selected'); 
			});
		} 
		//修改获取车辆型号
		function checkSelect(vehiclename){
			//<c:forEach items="${tRealsche.tRealscheVehiList}" var="item">
			if("${item.vehiclename}"==vehiclename){
				return true;
			}
			//</c:forEach>
			return false;
		}
		//修改获取车辆车牌号
		function checkBusid(dataid, busid){
			if(dataid == busid){
				return true;
			}
			return false;
		}
		//通过汽车车牌号显示汽车信息
		function setvalue(busid,prefix) {
			var selected = prefix+"_busid"+" option:selected";
			var maindriver = prefix+"_maindriver";
			var mobile = prefix+"_mobile";

			$(maindriver).val($(selected).attr("data-drvname"));
			$(mobile).val($(selected).attr("data-mobile"));
		}
		function keypresstwo(busid,prefix){
			var vehiclename = prefix+"_vehiclename";
			var maindriver = prefix+"_maindriver";
			var mobile = prefix+"_mobile";
			
			
			url = "${ctx}/schedef/tSchedef/ajaxList";
			 $.ajax({
		          dataType: 'json',
		            url:url,
		            data:{busid:busid},
		            type: 'POST',
		            success: function(data) {
		            	console.log(data);
		            	 var obj = eval(data);
		            	
		            	 $(maindriver).val(obj[0].drvname);
		            	 $(vehiclename).val(obj[0].vehiclename);
		            	 $(mobile).val(obj[0].mobile);
		            },
		            error: function() {
		            		 alert("数据有误");
		            }
		        });     
		} 

</script>
</head>
<body>

	<ul class="nav nav-tabs">
		<li ><a href="${ctx}/orders/tOrders/busOrderList">订单一览</a></li>
		<%-- <li><a href="${ctx}/realsche/tRealsche/rentlist">待调度</a></li> --%>
		<li><a href="${ctx}/realsche/tRealsche/dispatchedlist">已调度</a></li>
		<li class="active"><a href="${ctx}/realsche/tRealsche/rentdispform?id=${tRealsche.realscheid}">已调度信息</a></li>
	</ul>
	<br />
	<input id="tRealscheVehiLists" name="tRealscheVehiLists" type="hidden"
		value="${fns:toJson(tRealsche.tRealscheVehiList)}" />
	<%-- <input type="hidden" id="trealscheb" name="trealscheb"
		value="${tRealscheBoardJson}"> --%>
	<form:form id="inputForm" modelAttribute="tRealsche"
		action="${ctx}/realsche/tRealsche/dispatchrent" method="post"
		class="form-horizontal">
		<form:hidden path="id" />
		<sys:message content="${message}" />
		<div class="control-group">
			<label class="control-label">订单名称：</label>
			<div class="controls">
				<form:input path="schename" htmlEscape="false" maxlength="64" readonly="true"
					class="span4 required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">订单日期：</label>
			<div class="controls">
			<input type='text'	readonly value='<fmt:formatDate value="${tRealsche.order.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>' class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">出发地：</label>
			<div class="controls">
				<input type='text'	readonly value="${tRealsche.boardaddr}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">目的地：</label>
			<div class="controls">
				<input type='text'	readonly value="${tRealsche.offaddr}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">上(下)车地点：</label>
			<div class="controls">
				<input type='text' class="span4" readonly value ='${tRealsche.order.boardaddr }'/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">发车日期：</label>
			<div class="controls">
			<input type='text'	readonly value='<fmt:formatDate value="${tRealsche.order.departdate}" pattern="yyyy-MM-dd HH:mm:ss"/>' class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">包车天数：</label>
			<div class="controls">
			<input type='text'	readonly value="${tRealsche.order.bookingdays}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">车型：</label>
			<div class="controls">
			<input type='text'	readonly value="${tRealsche.order.cartype.typename}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">品牌：</label>
			<div class="controls">
			<input type='text'	readonly value="${tRealsche.order.cartype.typedesc}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系人：</label>
			<div class="controls">
			<input type='text'	readonly value="${tRealsche.order.contacts}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系电话：</label>
			<div class="controls">
			<input type='text'	readonly value="${tRealsche.order.payertel}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">行程备注：</label>
			<div class="controls">
				<textarea  readonly style="width:290px;height:100px;">${tRealsche.order.remarks}</textarea>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">订单金额：</label>
			<div class="controls">
			<input type='text'	readonly value="${tRealsche.order.dueamount}" class="span4"/>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">车队报价：</label>
			<div class="controls">
			<input type='text'	readonly value="${tRealsche.offermount}" class="span4"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">调度信息：</label>
			<div class="controls">
				<table id="contentTable"
					class="table table-striped table-bordered table-condensed">
					<thead>
						<tr>
							<th class="hide"></th>
							<th>车牌号</th>
							<th>主司机</th>
							<th>司机电话</th>
							<th>司机确认</th>
						</tr>
					</thead>
					<tbody id="tRealscheVehiList">
					</tbody>
				</table>
				<script type="text/template" id="tRealscheVehiTpl">
						<tr id="tRealscheVehiList{{idx}}">
							<td class="hide">
								<input id="tRealscheVehiList{{idx}}_id" name="tRealscheVehiList[{{idx}}].id" type="hidden" {{if row}}value="{{row.id}}"{{/if}}/>							
							</td>
							<td>
								<select id="tRealscheVehiList{{idx}}_busid" name="tRealscheVehiList[{{idx}}].busid" disabled="true" class="input-xxlarges required" 
								onchange="setvalue(this.options[this.options.selectedIndex].value,'#tRealscheVehiList{{idx}}')">	   
  								<option value="">--请选择--</option>
								<c:forEach items="${buslist}" var="buslist">
  									<option 
										data-drvname="${buslist.drvname}"
										data-mobile="${buslist.mobile}"
										data-maindriver="${buslist.maindriver}"
										value ="${buslist.busid}" {{if row}}{{if row.busid == '${buslist.busid}' }}selected="selected"{{/if}}{{/if}}>${buslist.licenseno}</option>
								</c:forEach>  
								</select>		
							</td>
							<td>
								<input id="tRealscheVehiList{{idx}}_maindriver" name="tRealscheVehiList[{{idx}}].maindriver" type="text" {{if row}}value="{{row.maindriver}}"{{/if}} maxlength="50" class="input-small required" readonly/>
							</td>
							<td>
								<input id="tRealscheVehiList{{idx}}_mobile" name="tRealscheVehiList[{{idx}}].mobile" type="text" {{if row}}value="{{row.mobile}}"{{/if}} maxlength="50" class="input-small required" readonly/>
							</td>
							<td><input id="tRealscheVehiList{{idx}}_drvconfirmed" name="tRealscheVehiList[{{idx}}].drvconfirmed" type="text" {{if row}}value="{{row.drvconfirmed}}"{{/if}} maxlength="50" class="input-small required" readonly/>
								</td>
						</tr>
					</script>
				<script type="text/javascript">

					</script>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnCancel" class="btn" type="button" value="返 回"
				onclick="history.go(-1)" />
		</div>
	</form:form>

</body>
<script type="text/javascript">
 
</script>
</html>